﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Mail;
using System.Text;
using System.Threading.Tasks;
using BDShop.Entities;

namespace BDShop.Framework.Web
{
    public static class EmailHelper
    {
        public static void SendEMail(EmailComplex email)
        {
            SmtpClient client = new SmtpClient();
            client.DeliveryMethod = SmtpDeliveryMethod.Network;
            client.EnableSsl = email.EnableSsl;
            client.Host = email.SMTP;
            client.Port = email.Port;

            System.Net.NetworkCredential credentials = new System.Net.NetworkCredential(email.UserName,email.Password);
            client.UseDefaultCredentials = false;
            client.Credentials = credentials;

            MailMessage msg = new MailMessage();
            msg.From = new MailAddress(email.From);
            msg.To.Add(new MailAddress(email.To));

            msg.Subject = email.Subject;
            msg.IsBodyHtml = email.IsBodyHtml;
            msg.Body = email.Body;

            client.Send(msg);
        }
    }
}
